//
//  NetRequest+user.m
//  DogeLegs
//
//  Created by 宋华 on 2017/8/17.
//  Copyright © 2017年 宋华. All rights reserved.
//

#import "NetRequest+user.h"

@implementation NetRequest (user)

/**
 *  用户注册
 *
 *  @param params  注册的参数
 *  @param success 成功后的回调
 *  @param fail    失败后的回调
 *
 *  @return 会话任务
 */
- (NSURLSessionDataTask *)registDictionary:(NSDictionary *)params
                                   success:(void (^)(UserMode *user))success
                                      fail:(void (^)(RequestError *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kRegistUrl
                                                paramsDictionary:params
                                                interfaceVersion:nil
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess) {//需要实现
                                                                 UserMode *user = [UserMode userModeFromDict:data];
                                                                 if (success) {
                                                                     success(user);
                                                                 }
                                                                 
                                                             }else {
                                                                 fail(msg);
                                                                 
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg);
                                                             
                                                         }];
    
    return dataTask;
}

/**
 *  用户登录
 *
 *  @param params  登录的参数
 *  @param success 成功后的回调
 *  @param fail    失败后的回调
 *
 *  @return 会话任务
 */
- (NSURLSessionDataTask *)loginDictionary:(NSDictionary *)params
                                  success:(void (^)(UserMode *user))success
                                     fail:(void (^)(RequestError *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kLoginAppUrl
                                                paramsDictionary:params
                                                interfaceVersion:nil
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess) {//需要实现
                                                                 UserMode *user = [UserMode userModeFromDict:data];
                                                                 if (success) {
                                                                     success(user);
                                                                 }
                                                                 
                                                             }else {
                                                                 fail(msg);
                                                                 
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg);
                                                             
                                                         }];
    
    return dataTask;

}


/*
 @brief 登出
 @param success 成功回调
 @param fail 失败回调
 */
- (NSURLSessionDataTask *)loginOutDictionary:(NSDictionary *)params
                                     success:(void (^)(BOOL isSucess))success
                                        fail:(void (^)(NSString *error))fail {

    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kLogOutAppUrl
                                                paramsDictionary:params
                                                interfaceVersion:nil
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess){
                                                                 success(isSuccess);
                                                             }else {
                                                                 fail(msg.errorMsg);
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg.errorMsg);
                                                         }];
    return dataTask;
}


/*
 @brief 获取验证码
 @param success 成功回调
 @param fail 失败回调
 */
- (NSURLSessionDataTask *)getVerificationCodeDictionary:(NSDictionary *)params
                                                success:(void (^)(BOOL isSucess))success
                                                   fail:(void (^)(RequestError *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kVerificationCodeUrl
                                                paramsDictionary:params
                                                interfaceVersion:InterfaceVersion_V1
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess){
                                                                 success(isSuccess);
                                                                 
                                                             }else {
                                                                 fail(msg);
                                                                 
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg);
                                                             
                                                         }];
    
    return dataTask;
}
/*
 @brief 修改消费者个人资料
 @param success 成功回调
 @param fail 失败回调
 */
- (NSURLSessionDataTask *)modifyUserInfoDictionary:(NSDictionary *)params
                                           success:(void (^)(BOOL isSucess))success
                                              fail:(void (^)(NSString *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:kUserNameUrl
                                                paramsDictionary:params
                                                interfaceVersion:InterfaceVersion_V1
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess){
                                                                 success(isSuccess);
                                                             }else {
                                                                 fail(msg.errorMsg);
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg.errorMsg);
                                                         }];
    
    return dataTask;

}

/*
 @brief 反馈意见
 @param success 成功回调
 @param fail 失败回调
 */
- (NSURLSessionDataTask *)feedBackDictionary:(NSDictionary *)params
                                     success:(void (^)(BOOL isSucess))success
                                        fail:(void (^)(RequestError *error))fail {
    NSURLSessionDataTask *dataTask = [self postDataFromURLScheme:KFeedbackUrl
                                                paramsDictionary:params
                                                interfaceVersion:InterfaceVersion_V1
                                                         success:^(id data, BOOL isSuccess, RequestError *msg) {
                                                             if (isSuccess){
                                                                 success(isSuccess);
                                                             }else {
                                                                 fail(msg);
                                                             }
                                                         }fail:^(RequestError *errMsg) {
                                                             fail(errMsg);
                                                         }];
    
    return dataTask;
}

@end
